//
//  CityHeadView.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2018/9/13.
//  Copyright © 2018年 DUONIU_MAC. All rights reserved.
//

import UIKit

@objc protocol CityHeadViewDelegate {
    @objc optional func selectCurrentCity(name:String) //选择当前城市
    @objc optional func selectVisitCity(name:String) //选择最近拜访城市
    @objc optional func selectPopularCity(name:String) //选择热门城市
}

class CityHeadView: UIView {
    
    weak var cityDelegate : CityHeadViewDelegate?

    let currentCityView = CurrentCityView()
    let visitCityView = VisitCityView()
    let popularCityView = PopularCityView()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.backgroundColor = UIColor.mineColor()
        
        currentCityView.currentDelegate = self
        visitCityView.visitDelegate = self
        popularCityView.popularDelegate = self
        
        self.addSubview(currentCityView)
        self.addSubview(visitCityView)
        self.addSubview(popularCityView)
        
        let allCityLabel = UILabel()
        allCityLabel.text = allCity
        allCityLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 16))
        self.addSubview(allCityLabel)
        
        currentCityView.snp.makeConstraints { (make) in
            make.left.right.top.equalToSuperview()
            make.height.equalTo(RATIO_H(maxNum: 50))
        }
        
        visitCityView.snp.makeConstraints { (make) in
            make.left.right.equalToSuperview()
            make.top.equalTo(currentCityView.snp.bottom)
            make.height.equalTo(RATIO_H(maxNum: 80))
        }
        
        popularCityView.snp.makeConstraints { (make) in
            make.left.right.equalToSuperview()
            make.top.equalTo(visitCityView.snp.bottom)
            make.height.equalTo(RATIO_H(maxNum: 200))
        }
        
        allCityLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(RATIO(maxNum: 8))
            make.top.equalTo(popularCityView.snp.bottom).offset(RATIO_H(maxNum: 10))
            make.width.greaterThanOrEqualTo(10)
            make.height.equalTo(RATIO_H(maxNum: 20))
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}

extension CityHeadView : CurrentCityViewDelegate,VisitCityViewDelegate,PopularCityViewDelegate {
    
    //MARK: 选择当前城市
    func selectCurrentCity(name: String) {
        self.cityDelegate?.selectCurrentCity!(name: name)
    }
    
    //MARK: 选择最近拜访城市
    func selectVisitCity(name: String) {
        self.cityDelegate?.selectVisitCity!(name: name)
    }
    
    //MARK: 选择热门城市
    func selectPopularCity(name: String) {
        self.cityDelegate?.selectPopularCity!(name: name)
    }
    
}
